package com.mdd.maduoduo.utils;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.mdd.maduoduo.R;

public class BottomSheetUtils {

    private BottomSheetDialog bottomSheetDialog;

    public BottomSheetUtils() {
    }

    @SuppressLint("MissingInflatedId")
    public BottomSheetDialog selectRoleAlert(final Activity context,SelectRoleListener listener) {
        bottomSheetDialog = new BottomSheetDialog(context);
        View view = LayoutInflater.from(context).inflate(R.layout.sheet_role, null);
        bottomSheetDialog.setContentView(view);

        TextView tvOne = view.findViewById(R.id.tvOne);
        TextView tvTwo = view.findViewById(R.id.tvTwo);
        TextView tvThree = view.findViewById(R.id.tvThree);
        TextView tvFour = view.findViewById(R.id.tvFour);
        TextView tvFive = view.findViewById(R.id.tvFive);
        TextView tvSix = view.findViewById(R.id.tvSix);
        TextView tvSeven = view.findViewById(R.id.tvSeven);
        TextView tvEight = view.findViewById(R.id.tvEight);
        TextView tvNine = view.findViewById(R.id.tvNine);

        tvOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.sureSelect(tvOne.getText().toString());
            }
        });

        tvTwo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.sureSelect(tvTwo.getText().toString());
            }
        });

        tvThree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.sureSelect(tvThree.getText().toString());
            }
        });

        tvFour.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.sureSelect(tvFour.getText().toString());
            }
        });

        tvFive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.sureSelect(tvFive.getText().toString());
            }
        });

        tvSix.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.sureSelect(tvSix.getText().toString());
            }
        });

        tvSeven.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.sureSelect(tvSeven.getText().toString());
            }
        });

        tvEight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.sureSelect(tvEight.getText().toString());
            }
        });

        tvNine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.sureSelect(tvNine.getText().toString());
            }
        });

        bottomSheetDialog.show();
        return bottomSheetDialog;
    }

    public interface SelectRoleListener {
        void sureSelect(String name);
    }

    public void dismiss() {
        if (bottomSheetDialog != null && bottomSheetDialog.isShowing()) {
            bottomSheetDialog.dismiss();
            bottomSheetDialog = null;
        }
    }
}
